import yaml
from PySide2.QtGui import QCursor, QPixmap
from PySide2.QtWidgets import QWidget, QFrame, QPushButton, QHBoxLayout, QGridLayout, \
    QLabel, QSizePolicy, QVBoxLayout, QStackedWidget
from PySide2.QtCore import Qt
from PySide2.QtCore import QObject, Signal
from qfluentwidgets import PushButton, PrimaryPushButton, ComboBox, SpinBox, Pivot, SegmentedWidget
from app.common.style_sheet import StyleSheet


class PivotInterface(QWidget):
    """ Pivot interface """
    Nav = SegmentedWidget
    def __init__(self, parent=None):
        super().__init__(parent=parent)
        self.pivot = self.Nav(self)
        self.stackedWidget = QStackedWidget(self)
        self.vBoxLayout = QVBoxLayout(self)
        self.vBoxLayout.addWidget(self.pivot, 0, Qt.AlignLeft)
        self.vBoxLayout.addWidget(self.stackedWidget)
        self.vBoxLayout.setContentsMargins(0, 0, 0, 0)
        StyleSheet.NAVIGATION_VIEW_INTERFACE.apply(self)
        self.stackedWidget.currentChanged.connect(self.onCurrentIndexChanged)

    def addSubInterface(self, widget: QLabel, objectName, text):
        widget.setObjectName(objectName)
        self.stackedWidget.addWidget(widget)
        self.pivot.addItem(
            routeKey=objectName,
            text=text,
            onClick=lambda: self.stackedWidget.setCurrentWidget(widget)
        )
    def onCurrentIndexChanged(self, index):
        widget = self.stackedWidget.widget(index)
        self.pivot.setCurrentItem(widget.objectName())